package com.yiqi.liebang.common.rongim.msg;

import android.os.Parcel;
import android.text.TextUtils;

import com.suozhang.framework.utils.logger.Logger;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

import io.rong.common.ParcelUtils;
import io.rong.common.RLog;
import io.rong.imlib.MessageTag;
import io.rong.imlib.model.MessageContent;
import io.rong.imlib.model.UserInfo;


@MessageTag(value = "RC:SimpleMsg", flag = MessageTag.ISCOUNTED | MessageTag.ISPERSISTED)
public class CustomizeMessage extends MessageContent {


    private static final String TAG = "CustomizeMessage";
    public static final String CONTACT_OPERATION_REQUEST = "Request";
    public static final String CONTACT_OPERATION_ACCEPT_RESPONSE = "AcceptResponse";
    public static final String CONTACT_OPERATION_REJECT_RESPONSE = "RejectResponse";
    private String operation;
    private String sourceUserId;
    private String targetUserId;
    private String message;
    private String extra;

    private String content;
    private int isEducation;            //教育经历认证（0 未认证 1已认证）
    private String userUid;             //用户唯一id
    private String userName;           //用户姓名
    private int isBasic;         //基本信息认证（0：未认证 1：已认证）
    private String userNamePY;
    private int isOccupation;       //职业精力认证（0 未认证 1已认证）
    private String userHead;          //用户头像
    private String position;          //用户职位
    private String mechanism;          //机构信息认证（0：未认证 1：已认证）

    private String comLogo;
    private String company;
    private String userClassify;
    private String userEmail;
    private String userWorkAddress;
    private String effectSocre;
    private String userPhone;
    private int phonePrivacy;
    private String phone;

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public int getPhonePrivacy() {
        return phonePrivacy;
    }

    public void setPhonePrivacy(int phonePrivacy) {
        this.phonePrivacy = phonePrivacy;
    }


    public CustomizeMessage() {

    }


    public static CustomizeMessage obtain(

            String operation,
            String sourceUserId,
            String targetUserId,
            String message,
            String extra,
            String content,
            int isEducation,
            String userUid,
            String userName,
            int isBasic,
            String userNamePY,
            int isOccupation,
            String userHead,
            String position,
            String mechanism,
            String comLogo,
            String company,
            String userClassify,
            String userEmail,
            String userWorkAddress,
            String effectSocre,
            String userPhone,
            int phonePrivacy,
            String phone

    ) {

        CustomizeMessage obj = new CustomizeMessage();
        obj.operation = operation;
        obj.sourceUserId = sourceUserId;
        obj.targetUserId = targetUserId;
        obj.message = message;
        obj.extra = extra;
        obj.content = content;
        obj.isEducation = isEducation;
        obj.userUid = userUid;
        obj.userName = userName;
        obj.isBasic = isBasic;
        obj.userNamePY = userNamePY;
        obj.isOccupation = isOccupation;
        obj.userHead = userHead;
        obj.position = position;
        obj.mechanism = mechanism;
        obj.comLogo = comLogo;
        obj.company = company;
        obj.userClassify = userClassify;
        obj.userEmail = userEmail;
        obj.userWorkAddress = userWorkAddress;
        obj.effectSocre = effectSocre;
        obj.userPhone = userPhone;
        obj.phonePrivacy = phonePrivacy;
        obj.phone=phone;
        return obj;
    }


    public static final Creator<CustomizeMessage> CREATOR = new Creator<CustomizeMessage>() {
        public CustomizeMessage createFromParcel(Parcel in) {
            return new CustomizeMessage(in);
        }

        public CustomizeMessage[] newArray(int size) {
            return new CustomizeMessage[size];
        }
    };


    public byte[] encode() {
        JSONObject jsonObj = new JSONObject();

        try {
            jsonObj.putOpt("operation", this.operation);
            jsonObj.putOpt("sourceUserId", this.sourceUserId);
            jsonObj.putOpt("targetUserId", this.targetUserId);
            if (!TextUtils.isEmpty(this.message)) {
                jsonObj.putOpt("message", this.message);
            }

            if (!TextUtils.isEmpty(this.getExtra())) {
                jsonObj.putOpt("extra", this.getExtra());
            }
            if (!TextUtils.isEmpty(this.getContent())) {
                jsonObj.putOpt("content", this.getContent());
            }


            jsonObj.putOpt("isEducation", this.getIsEducation());
            jsonObj.putOpt("phonePrivacy", this.getPhonePrivacy());

            if (!TextUtils.isEmpty(this.getUserUid())) {
                jsonObj.putOpt("userUid", this.getUserUid());
            }
            if (!TextUtils.isEmpty(this.getUserName())) {
                jsonObj.putOpt("userName", this.getUserName());
            }

            jsonObj.putOpt("isBasic", this.getIsBasic());

            if (!TextUtils.isEmpty(this.getUserNamePY())) {
                jsonObj.putOpt("userNamePY", this.getUserNamePY());
            }

            jsonObj.putOpt("isOccupation", this.getIsOccupation());

            if (!TextUtils.isEmpty(this.getUserHead())) {
                jsonObj.putOpt("userHead", this.getUserHead());
            }
            if (!TextUtils.isEmpty(this.getPosition())) {
                jsonObj.putOpt("position", this.getPosition());
            }
            if (!TextUtils.isEmpty(this.getMechanism())) {
                jsonObj.putOpt("mechanism", this.getMechanism());
            }
            if (!TextUtils.isEmpty(this.getComLogo())) {
                jsonObj.putOpt("comLogo", this.getComLogo());
            }
            if (!TextUtils.isEmpty(this.getCompany())) {
                jsonObj.putOpt("company", this.getCompany());
            }
            if (!TextUtils.isEmpty(this.getUserClassify())) {
                jsonObj.putOpt("userClassify", this.getUserClassify());
            }

            if (!TextUtils.isEmpty(this.getUserEmail())) {
                jsonObj.putOpt("userEmail", this.getUserEmail());
            }
            if (!TextUtils.isEmpty(this.getUserWorkAddress())) {
                jsonObj.putOpt("userWorkAddress", this.getUserWorkAddress());
            }
            if (!TextUtils.isEmpty(this.getEffectSocre())) {
                jsonObj.putOpt("effectSocre", this.getEffectSocre());
            }
            if (!TextUtils.isEmpty(this.getUserPhone())) {
                jsonObj.putOpt("userPhone", this.getUserPhone());
            }
            if (!TextUtils.isEmpty(this.getPhone())) {
                jsonObj.putOpt("phone", this.getPhone());
            }
            if (this.getJSONUserInfo() != null) {
                jsonObj.putOpt("user", this.getJSONUserInfo());
            }


        } catch (JSONException var4) {
            RLog.e("ContactNotificationMessage", "JSONException " + var4.getMessage());
        }

        try {
            return jsonObj.toString().getBytes("UTF-8");
        } catch (UnsupportedEncodingException var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public CustomizeMessage(byte[] data) {
        String jsonStr = null;

        try {
            jsonStr = new String(data, "UTF-8");
        } catch (UnsupportedEncodingException var5) {
            var5.printStackTrace();
        }

        try {
            JSONObject jsonObj = new JSONObject(jsonStr);
            this.setOperation(jsonObj.optString("operation"));
            this.setSourceUserId(jsonObj.optString("sourceUserId"));
            this.setTargetUserId(jsonObj.optString("targetUserId"));
            this.setMessage(jsonObj.optString("message"));
            this.setExtra(jsonObj.optString("extra"));
            this.setContent(jsonObj.optString("content"));
            this.setIsEducation(jsonObj.optInt("isEducation"));
            this.setUserUid(jsonObj.optString("userUid"));
            this.setUserName(jsonObj.optString("userName"));
            this.setIsBasic(jsonObj.optInt("isBasic"));
            this.setUserNamePY(jsonObj.optString("userNamePY"));
            this.setIsOccupation(jsonObj.optInt("isOccupation"));
            this.setUserHead(jsonObj.optString("userHead"));
            this.setPosition(jsonObj.optString("position"));
            this.setMechanism(jsonObj.optString("mechanism"));
            this.setComLogo(jsonObj.optString("comLogo"));
            this.setCompany(jsonObj.optString("company"));
            this.setUserClassify(jsonObj.optString("userClassify"));
            this.setUserEmail(jsonObj.optString("userEmail"));
            this.setUserWorkAddress(jsonObj.optString("userWorkAddress"));
            this.setEffectSocre(jsonObj.optString("effectSocre"));
            this.setUserPhone(jsonObj.optString("userPhone"));
            this.setPhonePrivacy(jsonObj.optInt("phonePrivacy"));
            this.setPhone(jsonObj.optString("phone"));
            if (jsonObj.has("user")) {
                this.setUserInfo(this.parseJsonToUserInfo(jsonObj.getJSONObject("user")));
            }
        } catch (JSONException var4) {
            RLog.e("CustomizeMessage", "JSONException " + var4.getMessage());
        }

    }

    public CustomizeMessage(Parcel in) {
        this.operation = ParcelUtils.readFromParcel(in);
        this.sourceUserId = ParcelUtils.readFromParcel(in);
        this.targetUserId = ParcelUtils.readFromParcel(in);
        this.message = ParcelUtils.readFromParcel(in);
        this.extra = ParcelUtils.readFromParcel(in);
        this.content = ParcelUtils.readFromParcel(in);
        this.isEducation = ParcelUtils.readIntFromParcel(in);
        this.userUid = ParcelUtils.readFromParcel(in);
        this.userName = ParcelUtils.readFromParcel(in);
        this.isBasic = ParcelUtils.readIntFromParcel(in);
        this.userNamePY = ParcelUtils.readFromParcel(in);
        this.isOccupation = ParcelUtils.readIntFromParcel(in);
        this.userHead = ParcelUtils.readFromParcel(in);
        this.position = ParcelUtils.readFromParcel(in);
        this.mechanism = ParcelUtils.readFromParcel(in);
        this.comLogo = ParcelUtils.readFromParcel(in);
        this.company = ParcelUtils.readFromParcel(in);
        this.userClassify = ParcelUtils.readFromParcel(in);
        this.userEmail = ParcelUtils.readFromParcel(in);
        this.userWorkAddress = ParcelUtils.readFromParcel(in);
        this.effectSocre = ParcelUtils.readFromParcel(in);
        this.userPhone = ParcelUtils.readFromParcel(in);
        this.phonePrivacy = ParcelUtils.readIntFromParcel(in);
        this.phone = ParcelUtils.readFromParcel(in);
        try {
            this.setUserInfo(ParcelUtils.readFromParcel(in, UserInfo.class));
        } catch (Exception e) {
            Logger.e("Exception-----Msg>" + e.getMessage());
        }


    }


    public void writeToParcel(Parcel dest, int flags) {
        ParcelUtils.writeToParcel(dest, this.operation);
        ParcelUtils.writeToParcel(dest, this.sourceUserId);
        ParcelUtils.writeToParcel(dest, this.targetUserId);
        ParcelUtils.writeToParcel(dest, this.message);
        ParcelUtils.writeToParcel(dest, this.extra);
        ParcelUtils.writeToParcel(dest, this.content);
        ParcelUtils.writeToParcel(dest, this.isEducation);
        ParcelUtils.writeToParcel(dest, this.userUid);
        ParcelUtils.writeToParcel(dest, this.userName);
        ParcelUtils.writeToParcel(dest, this.isBasic);
        ParcelUtils.writeToParcel(dest, this.userNamePY);
        ParcelUtils.writeToParcel(dest, this.isOccupation);
        ParcelUtils.writeToParcel(dest, this.userHead);
        ParcelUtils.writeToParcel(dest, this.position);
        ParcelUtils.writeToParcel(dest, this.mechanism);
        ParcelUtils.writeToParcel(dest, this.comLogo);
        ParcelUtils.writeToParcel(dest, this.company);
        ParcelUtils.writeToParcel(dest, this.userClassify);
        ParcelUtils.writeToParcel(dest, this.userEmail);
        ParcelUtils.writeToParcel(dest, this.userWorkAddress);
        ParcelUtils.writeToParcel(dest, this.effectSocre);
        ParcelUtils.writeToParcel(dest, this.userPhone);
        ParcelUtils.writeToParcel(dest, this.phonePrivacy);
        ParcelUtils.writeToParcel(dest, this.phone);
        try {
            ParcelUtils.writeToParcel(dest, getUserInfo());
        } catch (Exception e) {
            Logger.e("Exception-----Msg>" + e.getMessage());
        }

    }

    public int describeContents() {
        return 0;
    }

    public String getOperation() {
        return operation;
    }

    public void setOperation(String operation) {
        this.operation = operation;
    }

    public String getSourceUserId() {
        return sourceUserId;
    }

    public void setSourceUserId(String sourceUserId) {
        this.sourceUserId = sourceUserId;
    }

    public String getTargetUserId() {
        return targetUserId;
    }

    public void setTargetUserId(String targetUserId) {
        this.targetUserId = targetUserId;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getExtra() {
        return extra;
    }

    public void setExtra(String extra) {
        this.extra = extra;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getIsEducation() {
        return isEducation;
    }

    public void setIsEducation(int isEducation) {
        this.isEducation = isEducation;
    }

    public String getUserUid() {
        return userUid;
    }

    public void setUserUid(String userUid) {
        this.userUid = userUid;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getIsBasic() {
        return isBasic;
    }

    public void setIsBasic(int isBasic) {
        this.isBasic = isBasic;
    }

    public String getUserNamePY() {
        return userNamePY;
    }

    public void setUserNamePY(String userNamePY) {
        this.userNamePY = userNamePY;
    }

    public int getIsOccupation() {
        return isOccupation;
    }

    public void setIsOccupation(int isOccupation) {
        this.isOccupation = isOccupation;
    }

    public String getUserHead() {
        return userHead;
    }

    public void setUserHead(String userHead) {
        this.userHead = userHead;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public String getMechanism() {
        return mechanism;
    }

    public void setMechanism(String mechanism) {
        this.mechanism = mechanism;
    }

    public String getComLogo() {
        return comLogo;
    }

    public void setComLogo(String comLogo) {
        this.comLogo = comLogo;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getUserClassify() {
        return userClassify;
    }

    public void setUserClassify(String userClassify) {
        this.userClassify = userClassify;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

    public String getUserWorkAddress() {
        return userWorkAddress;
    }

    public void setUserWorkAddress(String userWorkAddress) {
        this.userWorkAddress = userWorkAddress;
    }

    public String getEffectSocre() {
        return effectSocre;
    }

    public void setEffectSocre(String effectSocre) {
        this.effectSocre = effectSocre;
    }

    public String getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(String userPhone) {
        this.userPhone = userPhone;
    }
}